package 队列;

import java.util.Stack;

/*
 * https://leetcode-cn.com/problems/implement-queue-using-stacks/
 * */
public class _232_用栈实现队列 {

}

class MyQueue {
	private Stack<Integer> inStack;;
	private Stack<Integer> outStack;

	/** Initialize your data structure here. */
	public MyQueue() {
		inStack = new Stack<Integer>();
		outStack = new Stack<Integer>();
	}

	/** Push element x to the back of queue. */
	public void push(int x) {
		if (outStack.size() == 0) {
			outStack.push(x);
		} else {
			while (!outStack.isEmpty()) {
				inStack.push(outStack.pop());
			}
			inStack.push(x);
			while (!inStack.isEmpty()) {
				outStack.push(inStack.pop());
			}
		}

	}

	/** Removes the element from in front of queue and returns that element. */
	public int pop() {
		return outStack.pop();
	}

	/** Get the front element. */
	public int peek() {
		return outStack.peek();

	}

	/** Returns whether the queue is empty. */
	public boolean empty() {
		return inStack.isEmpty() && outStack.isEmpty();
	}
}

/**
 * Your MyQueue object will be instantiated and called as such: MyQueue obj =
 * new MyQueue(); obj.push(x); int param_2 = obj.pop(); int param_3 =
 * obj.peek(); boolean param_4 = obj.empty();
 */